<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时不可以修改本文件，影响升级覆盖
 */

class Jiaquan extends \Phpcmf\Home\Module
{
    public function  index(){
		$this->_json('0', '没有数据');		
	}
	public function  jiaquan_panduan() {
		//get 参数
		if(!$this->uid){
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //圈子id
		
			$jiaquan_tongji = \Phpcmf\Service::M()->db->table('1_quan_jiaquan')->where('quanid', $id)->countAllResults();
			$data = [
				'code' => 0,
				'data' => $jiaquan_tongji,
				'uid'=> 0,
			];
			$this->_json('1', '未登录',$data);								
		} else {
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$jiaquan_data = \Phpcmf\Service::M()->db->table('1_quan_jiaquan')->where('quanid', $id)->where('uid', $this->uid)->countAllResults();
			$jiaquan_tongji = \Phpcmf\Service::M()->db->table('1_quan_jiaquan')->where('quanid', $id)->countAllResults();
			//更新加入人数
			\Phpcmf\Service::M()->db->table('1_quan')->where('id', $id)->update(['jiaru_total'=>$jiaquan_tongji]);

			if($jiaquan_data){
				$data = [
					'code' => 1,
					'data' => $jiaquan_tongji,
					'uid'=> $this->uid,
	
				];
	
				$this->_json('1', '已加入',$data);
			} else {
				$data = [
					'code' => 2,
					'data' => $jiaquan_tongji,
					'uid'=> $this->uid,
	
				];

				$this->_json('0', '未加入',$data);
			}
		}
		
		
	}

}
